package com.atguigu.delivery.servlet;

import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpSession;

import java.io.IOException;

@WebServlet(urlPatterns = "/SysUserServletLogout")
public class SysUserServletLogout extends HttpServlet {

    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // 1、获取 session 对象
        HttpSession session = request.getSession();

        // 2、销毁 session 对象
        session.invalidate();

        // 3、重定向到登录页面
        response.sendRedirect(request.getContextPath() + "/login.jsp");
    }
}
